package {
import com.greatxin.utils.ColorUtils;
import flash.display.Sprite;

/**
 * 格子
 * @author daichangxin
 */
public class Grid extends Sprite
{
	private var _hCount:uint;
	private var _vCount:uint;
	private var _itemWidth:uint;
	private var _itemHeight:uint;
	
	public function Grid(hCount:uint, vCount:uint, itemWidth:uint, itemHeight:uint)
	{
		this._hCount = hCount;
		this._vCount = vCount;
		this._itemHeight = itemHeight;
		this._itemWidth = itemWidth;
		
		draw();
	}

	private function draw() : void
	{
		this.graphics.clear();
		
		for (var i : int = 0; i < this._vCount; i++) 
		{
			for (var j : int = 0; j < this._hCount; j++) 
			{
				var xPos:uint = (j % this._hCount) * this._itemWidth;
				var yPos:uint = (i % this._vCount) * this._itemHeight;
				
				this.graphics.beginFill(ColorUtils.getRandomColor(), .8);
				this.graphics.drawRect(xPos, yPos, this._itemWidth, this._itemHeight);
			}
		}
	}
}
}
